package org.amos.kafka.callback;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.SendResult;

@Slf4j
public class DefaultSendCallback implements SendCallback {
    @Override
    public void onSuccess(SendResult<String, Object> result) {
        // 根据业务系统需求自行设置，防止日志量过多浪费系统资源
        RecordMetadata rm = result.getRecordMetadata();
        log.info("[KafkaSender][DefaultSendCallback][{}]发送消息成功:{}", rm.topic(), result.toString());
    }

    @Override
    public void onFailure(SendResult<String, Object> result, Throwable ex) {
        ProducerRecord<String, Object> pr = result.getProducerRecord();
        log.error("[KafkaSender][{}]data:{},发送消息失败:{}", pr.topic(), pr.value(), ex.getMessage());
    }
}
